//
// Created by cmz2000 on 2021/8/4.
//

#include "main.h"

void display(unsigned short *oldID, unsigned short newID, int index, int level, SOCKADDR_IN clientAddr, char *recvBuf) {
    //调试等级为0，无任何输出
    if (level == 0);
        //调试等级为1
    else if (level == 1) {
        printf("\nThe requested domain name is: %s\n", URL);
        if (index == -1) {
            printf("Not found in the domain name resolution table!\n");
            printf("***************Relaying***************\n");
            printf("\tID Transformed: %d -> %d\n", *oldID, newID);
            printf("Client's IP is: %s\n", inet_ntoa(clientAddr.sin_addr));
        }
        else {
            printf("Found in the domain name resolution table!\n");
            if (strcmp(DNS_table[index].ip, "0.0.0.0") == 0) {
                printf("***************Shielding***************\n");
                printf("Domain name not exist!\n");
                printf("Client's IP is: %s\n", inet_ntoa(clientAddr.sin_addr));
            }
            else {
                printf("***************Server***************\n");
                printf("The query IP is: %s\n", DNS_table[index].ip);
                printf("Client's IP is: %s\n", inet_ntoa(clientAddr.sin_addr));
            }
        }
    }
        //调试等级为2
    else if (level == 2) {
        printf("\nThe requested domain name is: %s\n", URL);
        if (index == -1) {
            printf("Not found in the domain name resolution table!\n");
            printf("***************Relaying***************\n");
            printf("\tID Transformed: %d -> %d\n", *oldID, newID);
            printf("Client's IP is: %s\n", inet_ntoa(clientAddr.sin_addr));
            //以十六进制方式打印数据包内容
            for (int i = 0; i < BUF_SIZE; i++) {
                printf("%02x", recvBuf[i]);
                printf(" ");
            }
            printf("\n");
        }
        else {
            printf("Found in the domain name resolution table!\n");
            if (strcmp(DNS_table[index].ip, "0.0.0.0") == 0) {
                printf("***************Shielding***************\n");
                printf("Domain name not exist!\n");
                printf("Client's IP is: %s\n", inet_ntoa(clientAddr.sin_addr));
                for (int i = 0; i < BUF_SIZE; i++) {
                    printf("%02x", recvBuf[i]);
                    printf(" ");
                }
                printf("\n");
            }
            else {
                printf("***************Server***************\n");
                printf("The query IP is: %s\n", DNS_table[index].ip);
                printf("Client's IP is: %s\n", inet_ntoa(clientAddr.sin_addr));
                for (int i = 0; i < BUF_SIZE; i++) {
                    printf("%02x", recvBuf[i]);
                    printf(" ");
                }
                printf("\n");
            }
        }
    }
}
